<template>
  <view style="background-color: #181816; height: 100%;">
    <!-- logo -->
    <view class="big_logo">
      <image src="../../../static/big_logo.png"></image>
    </view>
    <!-- 名称 -->

    <!-- 版本号 -->
    <view class="version">{{ info.version ? info.version : `1.0.2` }}</view>
    <!-- 支持方 -->
    <view class="support_host">
      <!-- 至信链 -->
      <view class="ZXL">
        <image src="../../../static/zxl_logo.png"></image>
      </view>
    </view>
    <!-- 经营许可 -->
    <view class="ICP">ICP经营许可 京B2-20221836号</view>
    <!-- 隐私用户协议 -->
    <view class="agreement">
      <!--  -->
      <view class="agreement_link">
        <text @click="userAgreement">用户协议</text>
        与
        <text @click="privacyAgreement">隐私保护指引</text>
      </view>
      <view class="agreement-phone">联系电话:（010）53687780</view>
      <view class="copyright">Copyright © 2022</view>
    </view>
  </view>
</template>

<script>
import jWeixin from '@/node_modules/jweixin-module/lib/index.js'
export default {
  data() {
    return {
      info: {},
      ua: '',
      launch: false,
    }
  },
  mounted() {
    this.launch = true
    const url = location.href
    this.configSDK(url, {
      title: '卯时数字 - 进入我的',
      desc: '打造个人数字资产专属空间',
      link: 'https://h5.onedaen.com/pages/mine/mine',
      imgUrl: 'https://publish.onedaen.com/uploads/publicImg/shareLogo.png',
    })
    if (!this.ua) return
    document.getElementsByClassName('uni-page-head__title')[0].style.display =
      'none'
  },
  onShow() {
    if (!this.launch) return
    const url = location.href
    this.configSDK(url, {
      title: '卯时数字 - 进入我的',
      desc: '打造个人数字资产专属空间',
      link: 'https://h5.onedaen.com/pages/mine/mine',
      imgUrl: 'https://publish.onedaen.com/uploads/publicImg/shareLogo.png',
    })
  },
  onLoad(options) {
    const ua = window.navigator.userAgent.toLowerCase()
    this.ua = ua.match(/MicroMessenger/i) == 'micromessenger'
    this.init()
  },
  methods: {
    async init() {
      const info = uni.getAccountInfoSync()
      this.info = info.miniProgram
      console.log('info', this.info)
    },
    async configSDK(url, { title, desc, link, imgUrl }) {
      // const url = `https://h5.onedaen.com/pages/details/series_detail?id=${this.id}`

      const upUrl = encodeURIComponent(url)
      api.shareData({ url: upUrl }).then((res) => {
        jWeixin.config({
          debug: false, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来，若要查看传入的参数，可以在 pc 端打开，参数信息会通过 log 打出，仅在 pc 端时才会打印。
          appId: res.data.appId, // 必填，公众号的唯一标识
          timestamp: res.data.timestamp, // 必填，生成签名的时间戳
          nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
          signature: res.data.signature, // 必填，签名
          jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'], // 必填，需要使用的 JS 接口列表
        })

        jWeixin.ready(() => {
          // 分享给朋友
          jWeixin.updateAppMessageShareData({
            title, // 分享标题
            // desc: this.activity_detail.description, // 分享描述
            desc,
            link: res.data.url,
            imgUrl, // 分享图标
            success: () => {
              // 设置成功
              console.log('设置成功')
            },
          })
          // 分享到朋友圈
          jWeixin.updateTimelineShareData({
            title, // 分享标题
            link: res.data.url,
            imgUrl, // 分享图标
            success: () => {
              console.log('设置成功')
              // 设置成功
            },
          })
        })
      })
    },
    /* 用户协议 */
    userAgreement() {
      uni.navigateTo({
        url: '/pages/agreement/user_agreement',
      })
    },
    /* 隐私协议 */
    privacyAgreement() {
      uni.navigateTo({
        url: '/pages/agreement/privacy_agreement',
      })
    },
  },
}
</script>

<style lang="scss">
page {
  background-color: #181816;
}

.big_logo {
  height: 250rpx;
  width: 275rpx;
  margin: 150rpx auto 0 auto;

  image {
    height: 100%;
    width: 100%;
  }
}

.title {
  background-image: linear-gradient(-90deg, #f0c611 6%, #4effff 100%);
  background-clip: text;
  margin-top: 45rpx;
  text-align: center;
  letter-spacing: 3rpx;
  font-size: 45rpx;
  font-weight: bold;
  -webkit-background-clip: text;
  color: transparent;
}

.version {
  font-size: 32rpx;
  text-align: center;
  line-height: 100%;
  margin: 50rpx 0;
  color: #999999;
}

.support_host {
  width: 40%;
  margin: 200rpx auto 0 auto;

  .ZXL {
    width: 100%;

    image {
      height: 70rpx;
      width: 100%;
    }
  }
}
.ICP {
  width: 100%;
  font-size: 20rpx;
  color: #999999;
  text-align: center;
}
.agreement {
  display: flex;
  flex-direction: column;
  width: 50%;
  margin: 200rpx auto 0 auto;

  .agreement_link {
    color: #999999;
    font-size: 24rpx;
    text-align: center;

    text {
      color: #4effff;
    }
  }
  .agreement-phone {
    color: #fff;
    display: flex;
    align-items: center;
    font-size: 26rpx;
    margin: 20rpx 0;
    justify-content: center;
  }
  .copyright {
    font-size: 24rpx;
    color: #fff;
    text-align: center;
  }
}
</style>
